package com.kedao.util;

import java.util.*;

/*
 * 随机产生四位数字
 */
public class FourRandom {
	public static void main(String[] args) {
		int result = createNumber();
		System.out.println("result:" + result);
	}

	public static int createNumber() {
		int count = 0;
		int result = 0;
		List<Integer> list = new ArrayList<Integer>();
		while (true) {
			result = (int) (Math.random() * 10);
			if (count == 0) {
				if (result != 0) {
					list.add(result);
					count++;
				}
			} else {
				if (count == 4)
					break;
				if (list.contains(result))
					continue;
				else {
					list.add(result);
					count++;
				}
			}
		}
		return list.get(0) * 1000 + list.get(1) * 100 + list.get(2) * 10
				+ list.get(3);
	}
}
